Imports GeoFramework.Gps

Public Class UnderstandingPrecisionForm

    Private Sub GpsDevice_HorizontalDilutionOfPrecisionChanged(ByVal sender As Object, ByVal e As DilutionOfPrecisionEventArgs) Handles GpsDevice.HorizontalDilutionOfPrecisionChanged

        ' Update the slider bar to the current HDOP value  (up to 20)
        CurrentHorizontalDilutionOfPrecisionTrackBar.Value = Math.Min(e.DilutionOfPrecision.Value, 20)

        ' Also update the label to make it clear when readings are being accepted
        ' versus being ignored.
        If (CurrentHorizontalDilutionOfPrecisionTrackBar.Value <= MaximumDilutionOfPrecisionTrackBar.Value) Then
            PrecisionStatusLabel.Text = "Precision is currently good enough to accept positional readings."
            PrecisionStatusLabel.ForeColor = Color.Green
        Else
            PrecisionStatusLabel.Text = "Precision is currently not good enough.  Positional readings are being ignored."
            PrecisionStatusLabel.ForeColor = Color.Red
        End If
    End Sub

    Private Sub MaximumDilutionOfPrecisionTrackBar_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaximumDilutionOfPrecisionTrackBar.Scroll

        ' Set the maximum HDOP allowed in positional readings
        GpsDevice.MaximumHorizontalDilutionOfPrecision = _
            New DilutionOfPrecision(MaximumDilutionOfPrecisionTrackBar.Value)

        ' Also update the label to make it clear when readings are being accepted
        ' versus being ignored.
        If (CurrentHorizontalDilutionOfPrecisionTrackBar.Value <= MaximumDilutionOfPrecisionTrackBar.Value) Then
            PrecisionStatusLabel.Text = "Precision is currently good enough to accept positional readings."
            PrecisionStatusLabel.ForeColor = Color.Green
        Else
            PrecisionStatusLabel.Text = "Precision is currently not good enough.  Positional readings are being ignored."
            PrecisionStatusLabel.ForeColor = Color.Red
        End If
    End Sub

    Private Sub GpsDevice_PositionChanged(ByVal sender As Object, ByVal e As GeoFramework.PositionEventArgs) Handles GpsDevice.PositionChanged
        ' When precision is being enforced, this event will only fire when precision
        ' is good enough to accept positional readings.			 
        PositionLabel.Text = e.Position.ToString() + " at " + e.PositionTimeStamp.ToLocalTime().ToLongTimeString()
    End Sub
End Class